import { httpClient } from "@/common/httpClient";
import { Button, Col, Row } from "antd";
import React, { useState, useEffect } from "react";

interface IProps {}
const Test: React.FC = () => {
  const [data, setData] = useState<any[]>([]);
  useEffect(() => {
    // httpClient.get("/admin/device_register/detail?id=1", {}).then((res) => {
    //   setData(res.items || []);
    // });
    httpClient
      .post(
        "/cmd",
        'msg={"CID":10001,"PL":["SYS","UART","SOCK","VPN","CLIENTS","ROUTING","TRAFFIC"]}',
        {
          headers: {
            Authorization: "Basic YWRtaW46YWRtaW4=",
            "Content-Type": "application/json; charset=UTF-8",
            Accept: "text/plain",
            "Accept-Encoding": "gzip, deflate",
            "Accept-Language": "zh-CN,zh;q=0.9",
            Connection: "keep-alive",
            "x-requested-with": "XMLHttpRequest",
            origin: "http://192.168.1.235",
            referer: "http://192.168.1.235/",
          },
        }
      )
      .then((res) => {
        setData(res.items || []);
      });
  }, []);
  const hezha = (str: string) => {
    httpClient
      .get("/admin/device/detail", { cmd: str, device_id: 1 })
      .then((res) => {
        console.log(res);
      });
  };

  return (
    <div>
      <Button
        onClick={() => {
          hezha("1,E8FDF8467586,6,43522,3");
        }}
      >
        合闸
      </Button>
      <Button
        onClick={() => {
          hezha("1,E8FDF8467586,6,43521,3");
        }}
      >
        分闸
      </Button>
      {data.map((item: any, index: number) => {
        return (
          <div>
            <span>{item.registerName}</span>
            {item.getter?.extendsjsonobject?.options &&
              item.getter.extendsjsonobject.options.map(
                (item: any, index: number) => {
                  return item.choices.map((v: any) => {
                    return <div>{v.label}</div>;
                  });
                }
              )}
          </div>
        );
      })}
      {/* {data.map((item: any, index: number) => {
        return (
          <div key={index} style={{ border: "1px solid red", width: "100%" }}>
            <Row gutter={16}>
              {item &&
                typeof item === "object" &&
                Object.keys(item).map((k: string) => {
                  const value = item[k];
                  return (
                    <Col span={8} style={{ marginBottom: "30px" }}>
                      <span style={{ color: "#666666" }}>{k}: </span>
                      <span>
                        {value !== null && typeof value === "object"
                          ? JSON.stringify(value)
                          : String(value)}
                      </span>
                    </Col>
                  );
                })}
            </Row>
          </div>
        );
      })} */}
    </div>
  );
};

export default Test;
